package com.design.pattern;

/**
 * @author tonywang
 * @date 6/20/2018
 */
public class DecoratorPattern {
    public static void main(String[] args){
        ShapeDecorator circle = new CircleDecorator();

        ShapeDecorator redCircle = new RedShapeDecorator(new CircleDecorator());

        ShapeDecorator redRectangle = new RedShapeDecorator(new RectangleDecorator());
        System.out.println("Circle with normal border");
        circle.draw();

        System.out.println("\nCircle of red border");
        redCircle.draw();

        System.out.println("\nRectangle of red border");
        redRectangle.draw();
    }

}

interface ShapeDecorator {
    void draw();
}

class RectangleDecorator implements ShapeDecorator {

    @Override
    public void draw() {
        System.out.println("Shape: RectangleDecorator");
    }
}

class CircleDecorator implements ShapeDecorator {

    @Override
    public void draw() {
        System.out.println("Shape: CircleDecorator");
    }
}

abstract class ShapeDecoratorPattern implements ShapeDecorator {
    protected ShapeDecorator decoratedShape;

    public ShapeDecoratorPattern(ShapeDecorator decoratedShape){
        this.decoratedShape = decoratedShape;
    }

    public void draw(){
        decoratedShape.draw();
    }
}

class RedShapeDecorator extends ShapeDecoratorPattern {

    public RedShapeDecorator(ShapeDecorator decoratedShape) {
        super(decoratedShape);
    }

    @Override
    public void draw() {
        decoratedShape.draw();
        setRedBorder(decoratedShape);
    }

    private void setRedBorder(ShapeDecorator decoratedShape){
        System.out.println("Border Color: Red");
    }
}